//
//  ASDetailUserContentView.m
//  AvatarShow
//
//  Created by xunruiIOS on 2021/4/30.
//

#import "ASDetailUserContentView.h"

@implementation ASDetailUserContentView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.iconImage];
        [self addSubview:self.nickNameLab];
        [self addSubview:self.contentLab];
        [self addSubview:self.tagView];
        [self setAllViewLayout];
    }
    return self;
}

- (void)setAllViewLayout{
    @weakify(self);
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.top.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(42, 42));
    }];
    
    [self.nickNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.mas_equalTo(self.iconImage.mas_right).mas_offset(10);
        make.centerY.mas_equalTo(self.iconImage.mas_centerY);
        make.right.mas_equalTo(-10);
    }];
    
    [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.mas_equalTo(self.iconImage.mas_left);
        make.top.mas_equalTo(self.iconImage.mas_bottom).mas_offset(15);
        make.right.mas_equalTo(-10);
    }];
    
    [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(self.contentLab.mas_bottom).mas_offset(15);
        make.height.mas_equalTo(25);
    }];
}

- (UIImageView *)iconImage{
    if (!_iconImage) {
        _iconImage = [UIImageView new];
        _iconImage.layer.masksToBounds = YES;
        _iconImage.layer.cornerRadius = 21;
        _iconImage.layer.borderColor = [UIColor colorWithHexString:@"#FF7785"].CGColor;
        _iconImage.layer.borderWidth = 1.f;
        _iconImage.contentMode = UIViewContentModeScaleAspectFill;
        _iconImage.clipsToBounds = YES;
    }
    return _iconImage;
}

- (UILabel *)nickNameLab{
    if (!_nickNameLab) {
        _nickNameLab = [UILabel new];
        _nickNameLab.font = [UIFont systemFontOfSize:15];
        _nickNameLab.textColor = [UIColor colorWithHexString:@"#1A1A1A"];
    }
    return _nickNameLab;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab = [UILabel new];
        _contentLab.font = [UIFont systemFontOfSize:17];
        _contentLab.textColor = [UIColor colorWithHexString:@"#1A1A1A"];
//        _contentLab.numberOfLines = 0;
    }
    return _contentLab;
}

- (ASAvatarGroupTagView *)tagView{
    if (!_tagView) {
        _tagView = [[ASAvatarGroupTagView alloc]initWithFrame:CGRectZero];
    }
    return _tagView;
}


- (void)setModel:(ASHomeMainModel *)model{
    _model = model;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
    self.nickNameLab.text = model.nickname;
    self.contentLab.text = model.descriptionStr;
    if (model.tag_arr.count > 0) {
        self.tagView.hidden = NO;
        self.tagView.dataArr = model.tag_arr;
    }else{
        self.tagView.hidden = YES;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
